<?php

require('../public/connection.php');

checkLogin();

$data = (array)json_decode(file_get_contents("php://input", true));

if (empty($data["username"]) || empty($data["password"])) {
    die(json_encode(array("code" => 10010, "msg" => "json格式错误", "data" => null)));
}

$query = mysqli_query($connect, "update users set username='{$data["username"]}',password='{$data["password"]}' where id={$data["id"]};");

if (!$query) {
    die(json_encode(array("code" => 10040, "msg" => "修改数据失败，数据重复", "data" => null)));
}

die(json_encode(array("code" => 0, "msg" => "修改成功", "data" => null)));
